//
//  XMCellFactory.m
//  XMKit
//
//  Created by chenming on 2017/12/23.
//  Copyright © 2017年 ChenXiaoMing. All rights reserved.
//

#import "XMCellFactory.h"
// View
#import "XMBaseTableViewCell.h"

@implementation XMCellFactory

+ (XMBaseTableViewCell *)createCellWithClassName:(NSString *)cellClassName

                                     cellModel:(id)cellModel

                                     indexPath:(NSIndexPath *)indexPath {
    
    XMBaseTableViewCell *cell = nil;
    // 通过反射来定义cell，当遇到cell拓展时，可以直接用字符串反射，无需修改该工厂方法
    Class classForCell = NSClassFromString(cellClassName);
    // 初始化目标cell
    cell = [[classForCell alloc] initWithStyle:UITableViewCellStyleDefault
                               reuseIdentifier:cellClassName];
    [cell getDataSource:cellModel indexPath:indexPath];
    return cell;
    
}

/*
 UITableView中例子
 XMFactoryModel *dataModel = (XMFactoryModel *)_dataSource[indexPath.row];
 XMBaseTableViewCell *cell = nil;
     switch (dataModel.state) {
     case XMFactoryModelStyleFirst:
     {
         cell = [tableView dequeueReusableCellWithIdentifier:@"XMFirstTableViewCell"];
         if (nil == cell) {
             cell = [XMCellFactory createCellWithClassName:@"XMFirstTableViewCell" cellModel:dataModel indexPath:indexPath];
         }
     }
     break;
     case XMFactoryModelStyleSecond:
     {
         cell = [tableView dequeueReusableCellWithIdentifier:@"XMSecondTableViewCell"];
 
         if (nil == cell) {
             cell = [XMCellFactory createCellWithClassName:@"XMSecondTableViewCell"
             cellModel:dataModel
             indexPath:indexPath];
         }
     }
     break;
        default:
     break;
 }
 return cell;
*/
@end
